package book.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import book.pojo.Book;
import book.service.BookService;

@Controller("bookController")
public class BookController {
	
	@Autowired
	private BookService bookService;
	
	@RequestMapping("/bookList")
	public String getBookList(Model model) {
		List<Book> bookList = bookService.getBookList();
		model.addAttribute("books", bookList);
		return "bookList";
	}
	
	@RequestMapping(value="/bookList/{bclass}",method = RequestMethod.GET)
	public String getByClass(@PathVariable String bclass, Model model) {
		List<Book> bookList = bookService.getByClass(bclass);
		model.addAttribute("books", bookList);
		return "forward:/WEB-INF/jsp/bookList.jsp";
	}
	
	@RequestMapping("/bookDetail")
	public String getByID(String bookID, Model model) {
		Book book = bookService.getByID(bookID);
		model.addAttribute("book", book);
		return "bookDetail";
	}
	
}
